<template>
  <a-card :bordered="false">
    <a-tabs default-active-key="1" tab-position="top">
      <a-tab-pane key="1" tab="办理月报">
        <!-- 搜索条件 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline">
            <a-row :gutter="10">
              <a-col :md="6" :sm="12">
                <a-form-item label="办理年份">
                  <a-date-picker
                    :allowClear='false'
                    format="YYYY"
                    mode="year"
                    :value="year"
                    :open="open"
                    @openChange="openChange"
                    @panelChange="panelChange"
                  />
                </a-form-item>
              </a-col>

              <a-col :md="12" :sm="12">
            <span class="table-page-search-submitButtons" >
              <a-button type="primary" icon="search" @click='loadData'>查询</a-button>
            </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <!--      <a-button  type="primary" icon="bar-chart" @click='temporaryStatistics'>临时统计</a-button>-->
          <a-button  type="primary" icon="download" @click='downLoad'>导出</a-button>
          <a-button type="primary" style="margin-left: 8px"  @click='reloadMonth'>重新生成</a-button>
        </div>
        <a-spin :spinning='downLoading' tip=" 正在下载数据，请耐心等待">
          <a-table
            rowKey="id"
            ref="table"
            size="middle"
            bordered
            :scroll="{ x: 'max-content' }"
            class='table'
            :rowKey="record=>record.month"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="false"
            :loading="loading"
          >

       <span slot='action' v-show='record.monthId!=null' slot-scope='text, record,index'>
            <a @click='handleEdit(record)'> 编辑 </a>
            <a-divider  type='vertical' />
            <a @click='handleDetail(record.monthId)'> 详情 </a>
            <a-divider  type='vertical' />
             <a-dropdown>
            <a class="ant-dropdown-link">导出 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                   <a @click='downLoadTransfer(record.monthId)'> 导出转办工单 </a>
              </a-menu-item>
              <a-menu-item>
                <a @click='downLoadPretreatment(record.monthId)'> 导出预处理工单 </a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
      </span>


          </a-table>
        </a-spin>
        <order-detail-modal ref='orderModal'></order-detail-modal>
        <temporary-statistics-modal ref='temporary'></temporary-statistics-modal>
        <edit-statistics-modal ref='editModal' @updateOrder='loadData'></edit-statistics-modal>
        <reload-month-modal ref='reloadMonth'></reload-month-modal>
      </a-tab-pane>
      <a-tab-pane key="2" tab="临时统计">
        <handle-temporary-home></handle-temporary-home>
      </a-tab-pane>

    </a-tabs>





  </a-card>
</template>

<script>

import moment from 'moment/moment'
import ReportsHandleMonthlyService from '@/myService/ReportsHandleMonthlyService'
import OrderDetailModal from '@views/data-governance/smart-reports/handle-monthly/components/OrderDetailModal'
import ReportsEpidemicDailyService from '@/myService/ReportsEpidemicDailyService'
import TemporaryStatisticsModal
  from '@views/data-governance/smart-reports/handle-monthly/components/TemporaryStatisticsModal'
import EditStatisticsModal from '@views/data-governance/smart-reports/handle-monthly/components/EditStatisticsModal'
import ReloadMonthModal from '@views/data-governance/smart-reports/handle-monthly/components/ReloadMonthModal'
import HandleTemporaryHome from '@views/data-governance/smart-reports/handle-monthly/HandleTemporaryHome'

export default {
  components: {
    OrderDetailModal,
    TemporaryStatisticsModal,
    EditStatisticsModal,
    ReloadMonthModal,
    HandleTemporaryHome,
  },
  data () {
    return {
      open: false,
      year:moment(new Date()).format("YYYY"),
      // 查询参数
      /* 数据源 */
      dataSource:[],
      // 表头
      columns: [
        {
          title: '月份',
          dataIndex: 'month',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          fixed: 'left',
        },{
          title: '全大市办件情况',
          children: [
            {
              title: '自办量',
              dataIndex: 'replyNum',
              align: 'center',
            },
            {
              title: '同比',
              dataIndex: 'replyYoy',
              align: 'center',
            },
            {
              title: '转办量',
              dataIndex: 'transferNum',
              align: 'center',
            },
            {
              title: '同比',
              dataIndex: 'transferYoy',
              align: 'center',
            },
            {
              title: '自办率',
              align: 'center',
              dataIndex: 'replyRate',
            },
            {
              title: '意见建议',
              align: 'center',
              dataIndex: 'opinionNum',
            },
            {
              title: '申诉类',
              align: 'center',
              dataIndex: 'appealNum',
            },
            {
              title: '求决类',
              align: 'center',
              dataIndex: 'decideNum',
            },
            {
              title: '揭发控告',
              align: 'center',
              dataIndex: 'exposeNum',
            },
            {
              title: '咨询类',
              align: 'center',
              dataIndex: 'adviceNum',
            },
            {
              title: '其他',
              align: 'center',
              dataIndex: 'otherNum',
            },
            {
              title: '重件',
              align: 'center',
              dataIndex: 'repeatNum',
            },
            {
              title: '重复率',
              align: 'center',
              dataIndex: 'repeatRate',
            },
            {
              title: '小计',
              align: 'center',
              dataIndex: 'total',
            },
            {
              title: '同比',
              dataIndex: 'totalYoy',
              align: 'center',
            },
            {
              title: '按期受理率',
              align: 'center',
              dataIndex: 'acceptOnTime',
            },
            {
              title: '按期答复率',
              align: 'center',
              dataIndex: 'replyOnTime',
            },
            {
              title: '回访核实率',
              align: 'center',
              dataIndex: 'returnVisit',
            },
            {
              title: '未评价件',
              align: 'center',
              dataIndex: 'notEvaluatedNum',
            },
            {
              title: '不满意件',
              align: 'center',
              dataIndex: 'dissatisfiedNum',
            },
            {
              title: '满意基本满意件',
              align: 'center',
              dataIndex: 'satisfiedNum',
            },
            {
              title: '满意率',
              align: 'center',
              dataIndex: 'satisfiedRate',
            },
            {
              title: '群众满意率',
              align: 'center',
              dataIndex: 'massSatisfiedRate',
            },
          ]
        },
        {
          title: '市中心办件情况',
          children: [
            {
              title: '自办量',
              dataIndex: 'centerReplyNum',
              align: 'center',
            },
            {
              title: '同比',
              dataIndex: 'centerReplyYoy',
              align: 'center',
            },
            {
              title: '转办量',
              align: 'center',
              dataIndex: 'centerTransferNum',
            },
            {
              title: '同比',
              dataIndex: 'centerTransferYoy',
              align: 'center',
            },
            {
              title: '自办率',
              align: 'center',
              dataIndex: 'centerReplyRate',
            },
            {
              title: '意见建议',
              align: 'center',
              dataIndex: 'centerOpinionNum',
            },
            {
              title: '申诉类',
              align: 'center',
              dataIndex: 'centerAppealNum',
            },
            {
              title: '求决类',
              align: 'center',
              dataIndex: 'centerDecideNum',
            },
            {
              title: '揭发控告',
              align: 'center',
              dataIndex: 'centerExposeNum',
            },
            {
              title: '咨询类',
              align: 'center',
              dataIndex: 'centerAdviceNum',
            },
            {
              title: '其他',
              align: 'center',
              dataIndex: 'centerOtherNum',
            },
            {
              title: '小计',
              align: 'center',
              dataIndex: 'centerTotal',
            },
            {
              title: '同比',
              dataIndex: 'centerTotalYoy',
              align: 'center',
            },
          ]
        },
        {
          title: '三方通话',
          children: [
            {
              title: '来电量',
              dataIndex: 'sfthCallNum',
              align: 'center',
            },
            {
              title: '接通率',
              align: 'center',
              dataIndex: 'sfthAnswerRate',
            },
          ]
        },
        {
          title: '操作',
          key: 'action',
          width: 200,
          align:'center',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      /* table加载状态 */
      loading:false,
      // 加载数据方法 必须为 Promise 对象
      downLoading:false,
    }
  },
  mounted () {
    this.year=moment(new Date()).format("YYYY");
    this.loadData()
  },
  methods: {
    moment,
    loadData() {
      this.loading=true;
      ReportsHandleMonthlyService.getHandleStatisticsByYear(this.year).then(res=>{
        if (res.success) {
          this.dataSource = res.result.records || res.result
        }
        else {
          this.$message.error(res.message)
        }
      }).finally(()=>{
        this.loading=false;
      })
    },
    reloadMonth(){
      this.$refs.reloadMonth.open();
      // this.year=moment(new Date()).format("YYYY");
      // this.loadData()
    },
    handleEdit(row){
      this.$refs.editModal.open(row)
    },
    handleDetail(month){
      this.$refs.orderModal.open(month)
    },
    openChange(status) {
      if (status) {
        this.open = true;
      } else {
        this.open = false;
      }
    },
    panelChange(value){
      this.year = moment(value).format("YYYY");
      this.open = false;
    },
    downLoad(){
      this.downLoading=true;
      ReportsHandleMonthlyService.generateExcelByYear(this.year).finally(
        ()=>{
          this.downLoading=false;
        }
      )
    },
    downLoadTransfer(month){
      this.downLoading=true;
      ReportsHandleMonthlyService.downloadTransferOrder(month).catch(err=>{
        this.$message.info("正在制作EXCEL，请稍后重试")
      }).finally(()=>{
        this.downLoading=false;
      })
    },
    downLoadPretreatment(month){
      this.downLoading=true;
      ReportsHandleMonthlyService.downloadPretreatmentOrder(month).catch(err=> {
        this.$message.info("正在制作EXCEL，请稍后重试")
      }).finally(()=>{
        this.downLoading=false;
      })
    },
    temporaryStatistics(){
      this.$refs.temporary.open()
    }
  },

}
</script>
